package com.david.mydemo.ctl_redis.message.config;

import com.david.mydemo.ctl_redis.message.listen.RedisUserMsgV1t1Handler;
import com.david.mydemo.ctl_redis.message.listen.RedisUserMsgV1t2Handler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Slf4j
//@Configuration
public class RedisListenerV1Config {

    @Autowired
    private RedisUserMsgV1t1Handler userMsg1Handler;

    @Autowired
    private RedisUserMsgV1t2Handler userMsg2Handler;

    @Bean
    public RedisMessageListenerContainer redisContainer(RedisConnectionFactory connectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(userMsg1Handler, new ChannelTopic("user-topic1"));
        container.addMessageListener(userMsg2Handler, new ChannelTopic("user-topic2"));
        return container;
    }
}
